package com.djl.hw02server.controller;

import com.djl.hw02server.domain.XmlUser;
import com.djl.hw02server.service.UserService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user/")
public class RestUserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "queryAll", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
    public List<XmlUser> queryList() {
        return userService.queryAll();
    }

    @RequestMapping(value = "queryAllXml", produces = MediaType.APPLICATION_XML_VALUE, method = RequestMethod.POST)
    public List<XmlUser> queryListXml() {
        return userService.queryAll();
    }

    @RequestMapping(value = "queryById/{id}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public XmlUser queryById(@PathVariable("id") int id) {
        return userService.queryById(id);
    }

    @RequestMapping(value = "queryByIdXml/{id}", produces = MediaType.APPLICATION_XML_VALUE, method = RequestMethod.GET)
    public XmlUser queryByIdXml(@PathVariable("id") int id) {
        return userService.queryById(id);
    }

}
